<template>
	<view class="page">
		<q-navbar title="评价列表" :isBack="true" />
		<view class="page_container">
			<view class="content" v-for="(v,i) in list" :key="i">
				<view class="userInfo">
					<view class="userName"> {{v.userName}}
						<span class="createTime">{{v.createTime}}</span>
					</view>
					<view class="score">{{v.score||0}}</view>
				</view>
				<view>{{v.content}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		components: {},
		props: {},
		data() {
			return {
				list: [],
				requestParams: {
					pageSize: 10,
					pageNum: 1,
					status: 0,
					userId: this.$s.get('userId'),
				},
				total: 0,
				loading: false,
				status: 'loadmore',
			}
		},
		watch: {},
		// 必须要在onReady生命周期，因为onLoad生命周期组件可能尚未创建完毕
		onReady() {},
		onLoad(options) {},
		onShow() {
			this.getList(1)
		},
		methods: {
			getList(e) {
				this.loading = true
				this.$api.listEvaluate(this.requestParams).then(res => {
					this.status = 'loadmore'
					console.log('评价列表', res.rows);
					if (e) {
						this.list = res.rows
						this.total = res.total
					} else {
						this.list.push(...res.rows)
					}
					this.loading = false
					if (this.list.length >= this.total) {
						this.status = 'nomore'
					} else {
						this.status = 'loadmore'
					}
				})
			},
		},
		// 加载
		onReachBottom() {
			if (!this.loading) {
				if (this.list.length >= this.total) return
				this.status = 'loading'
				this.requestParams.pageNum += 1
				this.getList()
			}
		},
	}
</script>

<style lang="scss" scoped>
	.page {
		min-height: 100vh;

		.page_container {
			padding: 30rpx;

			.content {
				display: flex;
				flex-direction: column;
				border-bottom: 2rpx solid #444;
				margin-bottom: 40rpx;

				.userInfo {
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-bottom: 20rpx;

					.userName {
						font-weight: 700;
						font-size: 32rpx
					}

					.createTime {
						font-weight: 400;
						font-size: 24rpx;
						margin-left: 20rpx;
						color: #797c83;
					}

					.score {
						background-color: #ff0000;
						color: #fff;
						border-radius: 50%;
						padding: 5rpx 15rpx;
					}
				}
			}
		}
	}
</style>